import os
from multiprocessing import Process

a=0
def work1():
    global a
    for i in range(1000000):
        a+=1
    print(f'进程号：{os.getpid()}---work1------a',a)
    print(f'父进程id：{os.getppid()}')

def work2():
    global a
    for i in range(1000000):
        a+=1
    # os.getpid()获取进程号
    print(f'进程号：{os.getpid()}---work2------a',a)

def main():
    # daemon设置进程是否作为守护进程，主进程执行结束，守护进程也会结束
    # p=Process(target=work1,daemon=True)
    p = Process(target=work1)
    p.start()
    p2=Process(target=work2)
    p2.start()


if __name__ == '__main__':
    print('主进程a:',a)
    main()